<style>
    .layui-form-label {
        width: 100px;
    }

    .layui-input-block {
        margin-left: 130px;
    }

    .el-input__inner,
    .el-cascader {
        /* height: auto !important; */
    }
</style>
<div class="rightcontent rc-bg-grey">
    <div class="rc-pagepadding ">
        <div class=" rc-pannel layui-form">
            <div class=" rc-pannel-header rc-pagepadding rc-bold">
                <i class="iconfont goback rc-pointer">&#xe62b;</i> 编辑站点角色
            </div>
            <div class="rc-pannel-body  rc-pagepadding">



                <div class="layui-form-item">
                    <label class="layui-form-label">角色名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="title" autocomplete="off" value="<?php echo $roleinfo['title'] ?>" lay-verify="required" class="layui-input" />

                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">选择权限</label>
                    <div class="layui-input-block">
                        <input type="text" id="menus" lay-verify="required" autocomplete="off">


                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">挂件权限</label>
                    <div class="layui-input-block">
                        <?php foreach ($widgets as  $widget) {
                        ?>
                            <input type="checkbox" <?php echo in_array($widget['ident'], $widgetidents) ? 'checked' : '' ?> value="<?php echo $widget['ident'] ?>" title="<?php echo $widget['title'] ?>" name="widgetidents[]" autocomplete="off">
                        <?php
                        } ?>



                    </div>
                </div>


                <div class="layui-form-item rc-margin-bottom0">
                    <div class="layui-input-block">
                        <button type="button" class="layui-btn layui-btn-primary layui-btn-sm" lay-submit lay-filter="submit">提交</button>
                        <button type="reset" class="layui-btn layui-btn-sm">重置</button>
                    </div>
                </div>

            </div>



        </div>

    </div>
</div>
<script src="/static/admin/lib/layui/modules/cascader/cascader.js"></script>
<script>
    layui.use(function() {

        var form = layui.form;

        var layCascader = layui.layCascader;
        var cascaderdata = '<?php echo $menus ?>';
        var cascaderdata_obj = eval("(" + cascaderdata + ")");

        var layCascader = layui.layCascader;
        var menuCascader = layCascader({
            elem: '#menus',
            filterable: true,
            options: cascaderdata_obj,
            clearable: true,
            props: {
                value: 'id',
                label: 'title',
                multiple: true
            }

        });


        function convertToNumbers(arr) {
            for (let i = 0; i < arr.length; i++) {

                arr[i] = Number(arr[i]);

            }
            return arr;
        }
        var menuidents = '<?php echo json_encode($menuidents); ?>';
        var menuidents_obj = eval("(" + menuidents + ")");

        menuCascader.setValue(menuidents_obj);


        form.on('submit(submit)', function(data) {

            var postdata = data.field;
            postdata.menuidents = menuCascader.getCheckedValues();

            $.ajax({
                url: '/admin/SiteRole/edit?id=<?php echo request()->get('id') ?>', //请求路径
                type: "POST", //请求方式
                data: postdata, // 默认写法
                success: function(data) {
                    if (data.code == 0) {
                        toastr_success("编辑成功", function() {
                            window.location.href = '/admin/SiteRole/index';
                        });
                    } else {
                        toastr_error(data.message);
                    }
                },
                error: function() {

                },

            });
        });



    });
</script>